/**   
 * @ClassName: ButtonController.java 
 * @Package com.vrv.controller.button 
 * @author LQ   
 * @date 2017年5月6日 下午5:36:13 
 * @version V1.0
 */
package com.vrv.controller.button;


import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.github.pagehelper.PageInfo;
import com.vrv.button.model.Button;
import com.vrv.button.service.ButtonService;
import com.vrv.common.annotation.SysLog;
import com.vrv.common.util.page.PageUtils;
import com.vrv.common.util.result.ResultMapper;

/** 
 * ButtonController:按钮Controller
 * @author LQ 
 */
@RestController
@RequestMapping("/sys/button")
public class ButtonController {
    
    @Autowired
    private ButtonService buttonService;
    
    /**
     * 按钮列表
     * @param page 页
     * @param limit 行
     * @return ResultMapper 结果集
     */
    @RequestMapping("/list")
    public ResultMapper list(Integer page, Integer limit){
        List<Button> list = buttonService.list(page, limit);
        PageInfo<Button> pageInfo = new PageInfo<Button>(list);
        PageUtils pageUtil = new PageUtils(list, pageInfo.getTotal(), limit, page);
        return ResultMapper.ok().put("page", pageUtil);
    }
    
    /**
     * 新增按钮
     * @param model 按钮实体
     * @return ResultMapper 结果集
     */
    @SysLog("新增按钮")
    @RequestMapping("/add")
    public ResultMapper save(@RequestBody Button model){
        //数据校验
        //verifyForm(menu);
        buttonService.add(model);
        return ResultMapper.ok();
    }
    
    /**
     * 按钮信息
     * @param code 按钮编号
     * @return ResultMapper 结果集
     */
    @RequestMapping("/info/{code}")
    public ResultMapper info(@PathVariable("code") Integer code){
        Button model = buttonService.getModelByCode(code);
        return ResultMapper.ok().put("button", model);
    }
    
    /**
     * 修改按钮
     * @param model 按钮实体
     * @return ResultMapper 结果集
     */
    @SysLog("修改按钮")
    @RequestMapping("/update")
    public ResultMapper update(@RequestBody Button model){
        buttonService.update(model);
        return ResultMapper.ok();
    }
    
    /**
     * 删除按钮
     * @param ids 编号数组
     * @return ResultMapper 结果集
     */
    @SysLog("删除按钮")
    @RequestMapping("/delete")
    public ResultMapper delete(@RequestBody Integer[] ids){
        buttonService.deleteBatch(ids);
        return ResultMapper.ok();
    }
    
}
